package hmvictor.jpql.nodes;

import hmvictor.jpql.Connection;
import hmvictor.jpql.ConnectionsTopComponent;
import javax.swing.Action;
import org.openide.nodes.AbstractNode;
import org.openide.nodes.Children;
import org.openide.util.actions.SystemAction;
import org.openide.util.lookup.Lookups;

/**
 *
 * @author Victor
 */
public class ConnectionNode extends AbstractNode{
    private final Action[] actions;
    private Action preferredAction;

    public ConnectionNode(Connection obj) {
        super (Children.LEAF, Lookups.singleton(obj));
        setDisplayName (obj.getName());
        setShortDescription(obj.getUrl());
        actions=new Action[]{new EditConnectionAction(this), new RemoveConnectionAction(this)};
        preferredAction=actions[0];
    }
    
    public ConnectionNode(ConnectionChildFactory f) {
        super (Children.create(f, true));
        setDisplayName ("Root");
        actions=new Action[]{new AddConnectionAction()};
    }

    @Override
    public Action[] getActions(boolean context) {
        return actions;
    }

    @Override
    public Action getPreferredAction() {
        return preferredAction;
    }

}
